//获取本地信息
var my_phone = localStorage.getItem("my_phone");
var user_id = localStorage.getItem("user_id");
var mask = mui.createMask(); //遮罩层
var limit = 10; //每页条数
var page = 1; //页数
var isOver = false; //是否加载完
var strip; //更新条数

mui.init({
	pullRefresh: {
		container: '#pullrefresh',
		up: {
			auto: true,
			contentrefresh: '正在加载...',
			contentnomore: '没有更多数据了',
			callback: pulldownRefresh
		}
	}
});

//判断ios
var u = navigator.userAgent;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
if(isiOS) {
	$(".mui-scroll-wrapper").css("padding-top", "44px")
}

//积分明细接口
function addData() {
	mui.ajax(integral_url + '/findDetailByIntegrType', {
		data: {
			"limit": limit,
			"page": page,
			"sign": "string",
			"user_id": user_id
		},
		dataType: 'json', //服务器返回json格式数据
		type: 'post', //HTTP请求类型
		timeout: 10000, //超时时间设置为10秒；
		headers: {
			'Content-Type': 'application/json'
		},
		success: function(data) {
			if(data.code == 10000) {
				strip = data.resp.length; //更新条数
				var p = data.total / limit; //总页数
				if(page >= p) { //当前的页数
					isOver = true;
					mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
					mui.toast("为您更新了" + strip + "条交易明细");
				}
				if(isOver == false) {
					page++;
					mui('#pullrefresh').pullRefresh().endPullupToRefresh(true); //停止正在加载
					mui('#pullrefresh').pullRefresh().enablePullupToRefresh(); //显示上拉加载文字
					mui.toast("为您更新了" + strip + "条交易明细");
				}
				var html = '';
				if(data.resp.length == 0) {
					var html = "";
					$(".mui-scroll-wrapper").html("<div class='No_detail'>暂无明细信息</div>");
				} else {
					for(var i = 0; i < data.resp.length; i++) {
						html += '<li class="mui-table-view-cell transaction_btn" transaction_id="' + data.resp[i].id + '">';
						html += '<span class="">' + data.resp[i].operatioMsg + '</span>';
						html += '<span class="">' + data.resp[i].integrType + '</span>';
						html += '<span class="mun">' + data.resp[i].number + '</span>';
						html += '<span class="">' + data.resp[i].updateTime.substr(0, 10) + '</span>';
						html += '</li>';
					}
					$('#list_detailed').append(html);
				}
			} else {
				mui.alert(data.msg);
			}
		},
		error: function(xhr, type, errorThrown) { //异常处理；
			console.log(type);
			var error_msg = JSON.parse(xhr.responseText);
			mui.alert(error_msg.msg);
		}
	});
}

//交易明记录跳转详情
mui("body").on("tap", ".transaction_btn", function() {
	var transaction_id = $(this).attr('transaction_id');
	mui.openWindow({
		url: "transaction_detail.html",
		extras: {
			transaction_id: transaction_id
		},
		createNew: true
	})
});

//页面进入执行方法
window.onload = function() {
	mui.plusReady(function() {
		self = plus.webview.currentWebview();
		plus.nativeUI.closeWaiting(); //关闭等待
	});
}
/**
 * 下拉刷新具体业务实现
 */
function pulldownRefresh() {
	setTimeout(function() {
		addData();
		mui('#pullrefresh').pullRefresh().endPullupToRefresh((isOver)); //参数为true代表没有更多数据了。 
	}, 1500);
}
